package com.aspose.cells;

import java.io.IOException;

class zatn extends com.aspose.cells.b.a.d.zm {
   private long a;
   private byte[] b;
   private int c;
   private int d;
   private int e;
   private int f;
   private boolean g;
   private boolean h;
   private boolean i;
   private boolean j;

   public zatn() throws Exception {
      this(0);
   }

   public zatn(int var1) throws Exception {
      this.a = 0L;
      if (var1 < 0) {
         throw new IllegalArgumentException("ArgRange_NonNegative\\r\\nParameter name: \"capacity");
      } else {
         this.b = new byte[var1];
         this.c = 0;
         this.d = var1;
         this.e = 0;
         this.f = 0;
         this.g = true;
         this.h = true;
         this.i = true;
         this.j = false;
      }
   }

   public void a() {
      this.j = true;
   }

   public void b() {
   }

   private void m() throws Exception {
      if (this.j) {
         throw new IOException("IO_StreamClosed");
      }
   }

   private void n() throws Exception {
      if (this.j) {
         throw new IOException("IO_StreamClosed");
      } else if (!this.h) {
         throw new IOException("IO_NotSupp_Write");
      }
   }

   private void a(int var1) throws Exception {
      if (!this.g) {
         throw new IOException("IO_FixedCapacity");
      } else {
         var1 -= this.c;
         if (var1 < 256) {
            var1 = 256;
         }

         if (var1 < (this.d - this.c) * 2) {
            var1 = (this.d - this.c) * 2;
         }

         byte[] var2 = new byte[var1];
         if (this.f > this.c) {
            System.arraycopy(this.b, this.c, var2, 0, this.f - this.c);
         }

         this.b = var2;
         this.d = var1;
         this.e -= this.c;
         this.f -= this.c;
         this.c = 0;
      }
   }

   public int a(byte[] var1, int var2, int var3) throws Exception {
      this.m();
      int var4 = this.f - this.e;
      if (var4 > var3) {
         var4 = var3;
      }

      if (var4 <= 0) {
         return 0;
      } else {
         System.arraycopy(this.b, this.e, var1, var2, var4);
         this.e += var4;
         return var4;
      }
   }

   public int c() throws Exception {
      if (!this.j) {
         return this.e < this.f ? this.b[this.e++] : -1;
      } else {
         throw new IOException("IO_StreamClosed");
      }
   }

   public long a(long var1, int var3) throws Exception {
      this.m();
      if (var1 > 2147483647L) {
         throw new IOException("IO_InvalidSeekPosition");
      } else {
         if (var3 == 0) {
            if (var1 < 0L) {
               throw new IOException("IO_InvalidSeekPosition");
            }

            try {
               this.e = this.c + (int)var1;
            } catch (NumberFormatException var7) {
               throw new IOException("IO_InvalidSeekPosition");
            }
         } else if (var3 == 1) {
            if (var1 + (long)this.e < (long)this.c) {
               throw new IOException("IO_InvalidSeekPosition");
            }

            try {
               this.e += (int)var1;
            } catch (NumberFormatException var6) {
               throw new IOException("IO_InvalidSeekPosition");
            }
         } else {
            if (var3 != 2) {
               throw new IllegalArgumentException("IO_InvalidWhence");
            }

            if (var1 + (long)this.f < (long)this.c) {
               throw new IOException("IO_InvalidSeekPosition");
            }

            try {
               this.e = this.f + (int)var1;
            } catch (NumberFormatException var5) {
               throw new IOException("IO_InvalidSeekPosition");
            }
         }

         return (long)this.e;
      }
   }

   public void a(long var1) throws Exception {
      if (!this.j && this.h) {
         if (var1 >= 0L && var1 <= (long)(Integer.MAX_VALUE - this.c)) {
            int var3 = this.c + (int)var1;
            if (var3 > this.d) {
               this.a(var3);
            } else if (var3 > this.f) {
               com.aspose.cells.b.a.za.a(this.b, this.f, var3 - this.f);
            }

            this.f = var3;
            if (this.e > var3) {
               this.e = var3;
            }

         } else {
            throw new IOException("IO_InvalidLength");
         }
      } else {
         throw new IOException("IO_NotSupp_SetLength");
      }
   }

   public void b(byte[] var1, int var2, int var3) throws Exception {
      this.n();
      int var4 = this.e + var3;
      if (var4 < 0) {
         throw new IOException("IO_WriteFailed");
      } else {
         if (var4 > this.f) {
            if (var4 > this.d) {
               this.a(var4);
            } else if (this.e > this.f) {
               com.aspose.cells.b.a.za.a(this.b, this.f, this.e - this.f);
            }

            this.f = var4;
         }

         System.arraycopy(var1, var2, this.b, this.e, var3);
         this.e = var4;
      }
   }

   public void a(byte var1) throws Exception {
      this.n();
      if (this.e == Integer.MAX_VALUE) {
         throw new IOException("IO_WriteFailed");
      } else {
         if (this.e >= this.f) {
            if (this.e >= this.d) {
               this.a(this.e + 1);
            } else if (this.e > this.f) {
               com.aspose.cells.b.a.za.a(this.b, this.f, this.e - this.f);
            }

            this.f = this.e + 1;
         }

         this.b[this.e++] = var1;
      }
   }

   public void a(com.aspose.cells.b.a.d.zm var1) throws Exception {
      this.m();
      if (var1 == null) {
         throw new IOException("stream");
      } else {
         var1.b(this.b, this.c, this.f - this.c);
      }
   }

   public boolean d() {
      return !this.j;
   }

   public boolean e() {
      return !this.j;
   }

   public boolean f() {
      return this.h && !this.j;
   }

   public void b_() throws Exception {
      this.a += this.h();
      this.c = 0;
      this.e = 0;
      this.f = 0;
   }

   public long h() throws Exception {
      this.m();
      return (long)(this.f - this.c);
   }

   public long i() throws Exception {
      this.m();
      return this.a + (long)this.e - (long)this.c;
   }

   public void b(long var1) throws Exception {
      this.m();
      if (var1 >= 0L && var1 <= 2147483647L) {
         try {
            this.e = this.c + (int)var1;
         } catch (NumberFormatException var4) {
            throw new IOException("IO_InvalidSeekPosition");
         }
      } else {
         throw new IOException("IO_InvalidSeekPosition");
      }
   }
}
